package cn.xfdzx.android.apps.shop.activity;


import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import butterknife.BindView;
import butterknife.OnClick;
import cn.xfdzx.android.apps.shop.R;
import cn.xfdzx.android.apps.shop.apps.Constants;
import cn.xfdzx.android.apps.shop.base.BaseMvpActivity;
import cn.xfdzx.android.apps.shop.bean.BaseObjectBean;
import cn.xfdzx.android.apps.shop.contract.FeedBackContract;
import cn.xfdzx.android.apps.shop.fragment.OneFragment;
import cn.xfdzx.android.apps.shop.presenter.FeedBackPresenter;
import cn.xfdzx.android.apps.shop.util.StatusBarUtil;

import static cn.xfdzx.android.apps.shop.activity.MainActivity.TYPE_IS_RETAIL;

public class FeedbackActivity extends BaseMvpActivity<FeedBackPresenter> implements FeedBackContract.View {

    @BindView(R.id.ll_state)
    LinearLayout llState;
    @BindView(R.id.tv_submit_feed)
    TextView tvSubmitFeed;
    @BindView(R.id.ett_feed)
    EditText ettFeed;
    @BindView(R.id.ett_phone)
    EditText ettPhone;
    private RelativeLayout.LayoutParams item_bar;

    @Override
    public int getLayoutId() {
        return R.layout.activity_feedback;
    }

    @Override
    public void initView() {
        initHigh();
        mPresenter = new FeedBackPresenter();
        mPresenter.attachView(this);
    }

    private void initHigh() {
        item_bar = (RelativeLayout.LayoutParams) llState.getLayoutParams();
        item_bar.height = StatusBarUtil.getStatusBarHeight(this);
        llState.setLayoutParams(item_bar);
        if ( TYPE_IS_RETAIL==0){
            tvSubmitFeed.setBackgroundResource(R.drawable.dfb9129_bg_r3);
        }else {
            tvSubmitFeed.setBackgroundResource(R.drawable.d02c557_bg_r3);
        }
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void onError(Throwable throwable) {

    }

    @Override
    public void onFeedBackSuccess(BaseObjectBean bean) {
        Toast.makeText(this, bean.getMsg(), Toast.LENGTH_SHORT).show();
        if (bean.getStatus() == Constants.SUCCESS_CODE) {
            finish();
        }
    }

    @OnClick({R.id.iv_back, R.id.tv_submit_feed})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                //返回
                finish();
                break;
            case R.id.tv_submit_feed:
                if (ettFeed.getText().toString().trim().isEmpty()) {
                    Toast.makeText(this, "请输入意见", Toast.LENGTH_SHORT).show();
                } else {
                    mPresenter.feedBack(ettFeed.getText().toString().trim(),ettPhone.getText().toString().trim());
                }
                break;

        }
    }

    @Override
    protected boolean isUseFullScreenMode() {
        return true;
    }
}
